package cn.tedu.lucky.draw.server.job.listener;

import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;

public class ActivityListener implements JobExecutionListener {
    /**
     * @param jobExecution 它代表了当前正在执行的批处理作业的实例，提供了对作业执行过程种的各种信息和状态的访问
     */
    @Override
    public void beforeJob(JobExecution jobExecution) {
        long begin = System.currentTimeMillis();
        /**
         * getExecutionContext()获取当前jobExecution相关联的ExecutionContext实例
         */
        jobExecution.getExecutionContext().putLong("begin",begin);
        System.err.println("-------作业开始执行，当前的时间是："+begin+"----------");
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        long end=System.currentTimeMillis();
        long begin = jobExecution.getExecutionContext().getLong("begin");
        System.err.println("-------作业执行结束，当前的时间是："+end+"----------");
        System.err.println("-------作业执行结束，当前花费的时间是："+(end-begin)+"----------");
    }
}
